<?php
$con = mysqli_connect('localhost', 'root', 'root');
if (!$con) {
    die('连接失败' . mysqli_connect_error());
}
mysqli_select_db($con, 'blog');
mysqli_set_charset($con, 'utf8');
$sql = "select b1.id,b1.title,b1.click,b1.create_time,b2.type_name from blog b1 inner join blog_type b2 on b1.blogtype_id=b2.type_id";
$result = mysqli_query($con, $sql);
$blog_list = [];
while ($row = mysqli_fetch_assoc($result)) {
    $blog_list[] = $row;
}
mysqli_close($con);
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>博客展示</title>
    <link href="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

</head>
<body>
<div class="container">
    <a href="index.html">返回导航</a>
    <a href="blog_add.php">发表博客</a>
    <table class="table">
        <tr>
            <th>编号</th>
            <th>标题</th>
            <th>类别</th>
            <th>点击率</th>
            <th>发表时间</th>
            <th>操作</th>
        </tr>
        <?php
        foreach ($blog_list as $key => $value) {
            ?>
            <tr>
                <td><?php echo $value['id'] ?></td>
                <td><?php echo $value['title'] ?></td>

                <td><?php echo $value['type_name'] ?></td>
                <td><?php echo $value['click'] ?></td>
                <td><?php echo $value['create_time'] ?></td>
                <td>
                    <a href="blog_edite.php?id=<?php echo $value['id'] ?>">编辑</a>
                    <a href="javascript:void(0)" onclick="del(<?php echo $value['id'] ?>)">删除</a>
                </td>
            </tr>
        <?php }
        ?>
    </table>
</div>
</body>
</html>
<script>
    function del(blog_id){
        if (confirm("确定要删除吗？")){
            //跳转页面
            window.location.href="blog_delete.php?id="+blog_id;
        }
    }

</script>
